Conversation
fixed bugs
adding a function that returns the value of an element from the top o…
…k-1-sem into SortingStation
fixed bugs
yurii-litvinov
left a comment
There was a problem hiding this comment.
Что-то неправильный ответ:
enter the expression in the infix form
1 - 2 + 3
1 2 3 + -
В инфиксной форме это (1 - 2) + 3, то есть 2, в постфиксной это 1 (2 3 +) -, то есть -4
Stack/Stack/Stack.c
Outdated
| char pop(Stack** head, int* error) | ||
| { | ||
| *error = 0; | ||
| if (*head != NULL) |
There was a problem hiding this comment.
Я бы тут обратил условие if на самом деле, чтобы весь содержательный код был не под if
sortStation/sortStation/Main.c
Outdated
| while (arrayToOutput[counter] != '\0') | ||
| { | ||
| printf("%c", arrayToOutput[counter]); | ||
| counter++; | ||
| } |
There was a problem hiding this comment.
Это же printf("%s", arrayToOutput);
sortStation/sortStation/Main.c
Outdated
| printf("enter the expression in the infix form\n"); | ||
| scanf_s("%[^\n]s", array, (unsigned)sizeof(array)); | ||
| int errorCode = 0; | ||
| char* arrayToOutput = translationIntoPostfixForm(array, &errorCode); |
There was a problem hiding this comment.
Можно аж так:
| char* arrayToOutput = translationIntoPostfixForm(array, &errorCode); | |
| const char* const arrayToOutput = translationIntoPostfixForm(array, &errorCode); |
| const char firstCorrectExpression[250] = "(7 - 6) * (7 - (6 - 4) * 2)"; | ||
| const char secondCorrectExpression[250] = "6 * (8 - 4) / 2 + 4"; | ||
| const char thirdCorrectExpression[250] = "3 - 4 * (5 + 5) / 2 + (7 - (4 - 6))"; | ||
| const char fourthCorrectExpression[250] = "2834 - 123 * (12 + 45 - (12 * (34 - 12) + 7))"; | ||
| const char fifthCorrectExpression[250] = "76 - 45 * (34 + 27)"; | ||
|
|
||
| const char firstIncorrectExpression[250] = "( 7 - 6 )"; | ||
| const char secondIncorrectExpression[250] = " 7-6"; | ||
| const char thirdIncorrectExpression[250] = "(7 - 3) * 4 - 5)"; | ||
| const char fourthIncorrectExpression[250] = "4 * ( 3 + 4)"; | ||
| const char fifthIncorrectExpression[250] = "12 - 8 / a "; |
There was a problem hiding this comment.
В этой задаче тоже можно было эти штуки прямо на месте писать, при вызове translationIntoPostfixForm
| #include "../../Stack/Stack/Stack.h" | ||
| #include <stdio.h> | ||
| #include <malloc.h> | ||
| #include <errno.h> |
| if (array[counter - 1] == ' ') | ||
| { | ||
| deleteStack(&head); | ||
| *errorCode = 4; |
There was a problem hiding this comment.
Как-то Вы нетолерантны к лишним пробелам (как я при проверке домашек прямо). Можно было их просто пропускать
| counter++; | ||
| continue; | ||
| } | ||
| arrayToOutput[counterForTheOutputArray] = array[counter]; |
There was a problem hiding this comment.
Можно было проще, просто при выводе чего-либо в arrayToOutput добавлять ещё и пробел
| int counterForTheOutputArray = 0; | ||
| int counter = 0; | ||
| int error = 0 ; | ||
| char* arrayToOutput = (char*)malloc(1000 * sizeof(char)); |
There was a problem hiding this comment.
Можно было length(array) + 1 выделять, или 2 * length(array) + 1, если хотим красиво с пробелами
| *errorCode = 4; | ||
| return NULL; | ||
| } | ||
| while (!isEmpty(head) && top(&head, &error) == '*' || top(&head, &error) == '/') |
There was a problem hiding this comment.
Вот тут бы скобки поставить. Кажется, у && больший приоритет, чем у ||
| } | ||
| while (top(&head, &error) != '(') | ||
| { | ||
| if(!isEmpty(head)) |
There was a problem hiding this comment.
| if(!isEmpty(head)) | |
| if (!isEmpty(head)) |
yurii-litvinov
left a comment
There was a problem hiding this comment.
Что-то эта домашка выбивается из структуры папок репозитория. А ещё, кстати, у Вас изменения к стеку делались не в ветке со стеком, а прямо в ветке конкретной задачи, так что чисто смерджить их в остальные задачи не получится. Надо навести порядок (то есть, может, неправильные коммиты откатить, и выложить изменения из них в ветку со стеком, а потом вмерджить её в ветки с задачами — только скопируйте себе решения куда-нибудь, а то сотрёте случайно всё). И ещё немного поправить.
Stack/Stack/Stack.c
Outdated
|
|
||
| int top(Stack** head, int* error) | ||
| { | ||
| *error = 0; |
There was a problem hiding this comment.
| *error = 0; | |
| *error = 0; |
| && strcmp("6 8 4 - * 2 / 4 +", translationIntoPostfixForm("6 * (8 - 4) / 2 + 4", &errors[1])) == 0 | ||
| && strcmp("3 4 5 5 + * 2 / - 7 4 6 - - +", translationIntoPostfixForm("3 - 4 * (5 + 5) / 2 + (7 - (4 - 6))", &errors[2])) == 0 | ||
| && strcmp("1 8 - 9 + 4 1 3 + * -", translationIntoPostfixForm("1 - 8 + 9 - 4 * (1 + 3)", &errors[3])) == 0 | ||
| && strcmp("1 2 - 3 +", translationIntoPostfixForm("1 - 2 + 3", &errors[4])) == 0 | ||
| && translationIntoPostfixForm("( 7 + * 2)", &errors[5]) == NULL | ||
| && translationIntoPostfixForm("7--", &errors[6]) == NULL | ||
| && translationIntoPostfixForm("(7 - 3) * 4 - 5)", &errors[7]) == NULL | ||
| && translationIntoPostfixForm("2 + 2)", &errors[8]) == NULL | ||
| && translationIntoPostfixForm("12 - 8 / a", &errors[9]) == NULL | ||
| && errors[0] == 0 | ||
| && errors[1] == 0 | ||
| && errors[2] == 0 | ||
| && errors[3] == 0 | ||
| && errors[4] == 0 | ||
| && errors[5] == 1 | ||
| && errors[6] == 1 | ||
| && errors[7] == 3 | ||
| && errors[8] == 3 | ||
| && errors[9] == 3; |
| void addSpace(char* symbol) | ||
| { | ||
| *symbol = ' '; | ||
| } |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| arrayToOutput[counterForTheOutputArray] = array[counter]; | ||
| counterForTheOutputArray++; | ||
| addSpace(&arrayToOutput[counterForTheOutputArray++]); |
There was a problem hiding this comment.
Вот эти три строчки стоило сделать отдельной функцией
| arrayToOutput[counterForTheOutputArray] = array[counter]; | ||
| counterForTheOutputArray++; | ||
| addSpace(&arrayToOutput[counterForTheOutputArray++]); |
There was a problem hiding this comment.
Кстати, counterForTheOutputArray++ тут — побочный эффект, нехорошо (запрещено стайлгайдом делать два действия за раз, потому что за этим тяжело уследить при беглом прочтении программы)
| { | ||
| *errorCode = 1; | ||
| deleteStack(&head); | ||
| return NULL; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| #include <malloc.h> | ||
| #include <string.h> | ||
|
|
||
| bool isRepeatTheOperation(char operation) |
| return operation == '+' || operation == '-' || operation == '*' || operation == '/'; | ||
| } | ||
|
|
||
| bool isPriorityForDivisionandMultiplication(char operation) |
There was a problem hiding this comment.
| bool isPriorityForDivisionandMultiplication(char operation) | |
| bool isPriorityForDivisionAndMultiplication(char operation) |
| return operation == '+' || operation == '-' || operation == '*' || operation == '/'; | ||
| } | ||
|
|
||
| bool isPriorityForDivisionandMultiplication(char operation) |
There was a problem hiding this comment.
Ну и я бы его назвал как просто isDivisionOrMultiplication, а лучше сделал бы функцию, которая бы по данному символу возвращала его приоритет в виде числа, и сравнивал бы числа
| } | ||
| while (top(&head, &error) != '(') | ||
| { | ||
| if(!isEmpty(head)) |
| #include <malloc.h> | ||
| #include <string.h> | ||
|
|
||
| bool isSecondOperationInRow(char operation) |
There was a problem hiding this comment.
Это скорее просто isOperation, в самой функции ничего про SecondInRow нет, а функция не должна делать предположений о том, как её будут использовать (иначе её тяжело будет использовать в другом контексте).
No description provided.